#include<iostream>
#include<amp.h>
#include<amp_math.h>
using namespace std;
using namespace concurrency;
using namespace concurrency::fast_math;
#include <light/environment_light.h>
#include"renderer\renderer.hpp"

int main()
{
	
	Scene scene;
	/*
	// cornell box
	P3 lookfrom(0, 1, 6.8);
	P3 lookat(0, 1, 5.8);
	P3 forward = lookat - lookfrom;
	P3 up(0, 1, 0);
	Float fovy = 19.5;
	Float aperture = 0.0;
	Float w = 1024, h = 1024;
	//Float focus = 3.5;
	Float focus = forward.len();

	Float rgb[3] = { 17,12,4 };
	Spectrum emission = Spectrum::FromRGB(rgb);
	scene.registerLightMaterial("Light", emission);

	scene.addMeshModel("res/scene/cornell-box/cornell-box.obj");
	*/
	
	// bedroom
	P3 lookfrom(3.456, 1.212, 3.299);
	P3 lookat(2.699, 1.195, 2.645);
	P3 forward = lookat - lookfrom;
	P3 up(-0.013, 1.000, -0.011);
	Float fovy = 39.4305;
	Float aperture = 0.0;
	Float w = 1200, h = 900;
	//Float focus = 3.5;
	Float focus = forward.len();

	Float rgb[3] = { 16.4648, 16.4648, 16.4648 };
	Spectrum emission = Spectrum::FromRGB(rgb)*2;
	scene.registerLightMaterial("Light", emission);
	P3 center = P3();
	BoundingBox world_bound;
	Float radius = 1e5;
	world_bound.mini = center - radius;
	world_bound.maxi = center + radius;
	//EnvironmentLight* light = new EnvironmentLight("res/envLight/valley.jpg", world_bound);
	//scene.add_light(light);

	scene.addMeshModel("res/scene/bedroom/bedroom.obj");
	
	/*
	// veach mis
	P3 lookfrom(0.0, 2.0, 15.0);
	P3 lookat(0.0, 1.69521, 14.0476);
	P3 forward = lookat - lookfrom;
	P3 up(0.0, 0.952421, -0.304787);
	Float fovy = 27.3909;
	Float aperture = 0.0;
	Float w = 1200, h = 900;
	//Float focus = 3.5;
	Float focus = forward.len();

	P3 rgb(901.803, 901.803, 901.803);
	Spectrum emission = Spectrum::FromRGB(&rgb[0]);
	scene.registerLightMaterial("Light1", emission);
	rgb = P3(100, 100, 100);
	emission = Spectrum::FromRGB(&rgb[0]);
	scene.registerLightMaterial("Light2", emission);
	rgb = P3(11.1111, 11.1111, 11.1111);
	emission = Spectrum::FromRGB(&rgb[0]);
	scene.registerLightMaterial("Light3", emission);
	rgb = P3(1.23457, 1.23457, 1.23457);
	emission = Spectrum::FromRGB(&rgb[0]);
	scene.registerLightMaterial("Light4", emission);
	rgb = P3(800, 800, 800);
	emission = Spectrum::FromRGB(&rgb[0]);
	scene.registerLightMaterial("Light5", emission);

	scene.addMeshModel("res/scene/veach-mis/veach-mis.obj");
	*/
	scene.initProperties();

	Camera cam(w, h, lookfrom, forward, up, fovy, aperture, focus);
	PT raytracer(false);
	Renderer renderer;
	renderer.set_camera(&cam);
	renderer.set_scene(&scene);
	renderer.set_ray_tracer(&raytracer);
	renderer.render("bedroom","256");
	/*
	Float t;
	SurfaceInteraction si;
	Ray current_ray;
	current_ray.o = P3(-0.858989, 2, 0.33431);
	current_ray.d = P3(-0.5776, -0.78036, -0.23967).norm();
	current_ray.o += current_ray.d * eps;
	bool intersect = scene.nearest_intersect(current_ray, &t, &si);
	fprintf(stdout, "check status");*/
	return 0;

}

